###Social Media Trolling - Replication###
###Victoria Dounoucos###

rm(list=ls())
library(readstata13)
library(foreign)
library(descr)
library(car)
library(MASS)
data <- read.dta13("C:/Users/vad11/Dropbox/Social Media Trolls/Data/State_Disclosure_13.dta")
attach(data)

##Recoding Variables##

#Gender#
table(data$female)
female <- as.numeric(data$female)
table(female)
female <- recode(female, "1=0; 2=1", as.numeric.result = TRUE, as.factor.result = FALSE)
table(female)

#Education#
table(data$educ)
education <- as.numeric(data$educ)
table(education)

#Age - age range: 19-76#
table(data$byear)
birthyear <- as.numeric(data$byear)
table(birthyear)
age <- (-birthyear) + 97
table(age)

#Social Media Use#
table(data$Q86_1)
data$Q86_1[is.na(data$Q86_1)] <- 0
table(data$Q86_1)

table(data$Q86_2)
summary(data$Q86_2)
data$Q86_2[is.na(data$Q86_2)] <- 0
table(data$Q86_2)

table(data$Q86_3)
summary(data$Q86_3)
data$Q86_3[is.na(data$Q86_3)] <- 0
table(data$Q86_3)

table(data$Q86_4)
summary(data$Q86_4)
data$Q86_4[is.na(data$Q86_4)] <- 0
table(data$Q86_4)

table(data$Q86_5)
summary(data$Q86_5)
data$Q86_5[is.na(data$Q86_5)] <- 0
table(data$Q86_5)


table(data$Q86_6)
summary(data$Q86_6)
data$Q86_6[is.na(data$Q86_6)] <- 0
table(data$Q86_6)

table(data$Q86_7)
summary(data$Q86_7)
data$Q86_7[is.na(data$Q86_7)] <- 0
table(data$Q86_7)

table(data$Q86_8)
summary(data$Q86_8)
data$Q86_8[is.na(data$Q86_8)] <- 0
table(data$Q86_8)

table(data$Q86_9)
summary(data$Q86_9)
data$Q86_9[is.na(data$Q86_9)] <- 0
table(data$Q86_9)

socialmedia <- data$Q86_1 + data$Q86_2 + data$Q86_3 + data$Q86_4 + data$Q86_5 + data$Q86_6 + data$Q86_7 + data$Q86_8 + data$Q86_9
table(socialmedia)

#Twitter Use (in past month)#
twitter <- data$Q86_2[is.na(data$Q86_2)] <- 0
twitter <- data$Q86_2
table(twitter)

#Party#
table(data$Q28)
republican <- as.numeric(data$Q28) #1=strong republican (29), 2=not strong (65)
table(republican)

table(data$Q29)
democrat <- as.numeric(data$Q29) #1=strong (115), 2=not strong (128)
table(democrat)

table(data$Q30)
independent <- as.numeric(data$Q30) #1=lean rep (35), 2=lean dem (73), 3=independent (55)
table(independent) 

party <- NA
party[democrat==1] <- 1
party[democrat==2] <- 2
party[independent == 2] <- 3
party[independent == 3] <- 4
party[independent == 1] <- 5
party[republican == 2] <- 6
party[republican == 1] <- 7
table(party) #strong democrat to strong republican (1-7)

#Income#
table(data$Q35)
income <- as.numeric(data$Q35)
table(income)
income <- recode(income, "1=5000; 2=17500; 3=37500; 4=62500; 5=87500; 6=125000; 7=175000; 8=200000", as.factor.result = FALSE, as.numeric.result = TRUE)
table(income)

#Ideology#
table(data$Q25)
ideology <- as.numeric(data$Q25)
table(ideology) #very liberal to very conservative (1-5)

#Political Interest#
table(data$polint)
interest <- as.numeric(data$polint)
table(interest) #no interest to all the time#

#Race - white/non-white dummy#
table(data$Q31_1)

table(data$Q31_2) #black

table(data$Q31_3) #asian

table(data$Q31_4) #hispanic/latino

table(data$Q31_5) #American indian

table(data$Q31_6) #Other

white <- NA
white[data$Q31_1==1] <- 1
white[data$Q31_2==1] <- 0 
white[data$Q31_3==1] <- 0
white[data$Q31_4==1] <- 0
white[data$Q31_5==1] <- 0
white[data$Q31_6==1] <- 0
table(white)

#Dummy for Treatment - Negative#
table(data$RO_BR_FL_18)
negative <- recode(data$RO_BR_FL_18, "'trt_neg' = 1; else=0", as.numeric.result = TRUE, as.factor.result = FALSE)
table(negative)

#Dummy for Treatment - Positive#
table(data$RO_BR_FL_18)
positive <- recode(data$RO_BR_FL_18, "'trt_pos' = 1; else=0", as.numeric.result = TRUE, as.factor.result = FALSE)
table(positive)

#Dummy for Treatment - Control#
table(data$RO_BR_FL_18)
control <- recode(data$RO_BR_FL_18, "'trt_ctrl' = 1; else=0", as.numeric.result = TRUE, as.factor.result = FALSE)
table(control)

#Manipulation Check -- 1=mostly positive, 2=neither, 3=mostly negative#
table(data$Q83)
manip <- data$Q83
manip <- recode(manip, "'Mostly positive'='1'; 'Neither positive nor negative'='2'; 'Mostly negative'='3'", as.factor.result = FALSE, as.numeric.result = TRUE)
table(manip)

PosManip_Pass <- data$Q83[positive==1]
table(PosManip_Pass)
PosManip_Pass <- recode(PosManip_Pass, "'Mostly positive' = '1'; 'Neither positive nor negative' = '0'; 'Mostly negative'='0'", as.factor.result = FALSE, as.numeric.result = TRUE)
table(PosManip_Pass)

crosstab(positive, manip)

positive_new <- NA
positive_new[positive==1 & manip == 1] <- 1
positive_new[positive==0] <- 0
table(positive_new)

NegManip_Pass <- data$Q83[negative==1]
table(NegManip_Pass)
NegManip_Pass <- recode(NegManip_Pass, "'Mostly positive'='0'; 'Neither positive nor negative'='0';'Mostly negative'='1'", as.factor.result = FALSE, as.numeric.result = TRUE)
table(NegManip_Pass)

negative_new <- NA
negative_new[negative==1 & manip==3] <- 1
negative_new[negative==0] <- 0
table(negative_new)

crosstab(negative, manip)


##Balance Tests##
mean(female[control==1]) #0.45
mean(female[positive==1]) #0.43
mean(female[negative==1]) #0.41
summary(aov(female ~ data$RO_BR_FL_18)) #p-value=0.78

mean(education[control==1]) #4.27
mean(education[positive==1]) #4.09
mean(education[negative==1]) #4.07
summary(aov(education ~ RO_BR_FL_18)) #p-value=0.31

mean(na.omit(age[control==1])) #37.03 
mean(na.omit(age[positive==1])) #34.59
mean(na.omit(age[negative==1])) #33.95
summary(aov(age~RO_BR_FL_18)) #p-value=0.03

mean(socialmedia[control==1]) #3.83
mean(socialmedia[positive==1]) #3.89
mean(socialmedia[negative==1]) #3.81
summary(aov(socialmedia~RO_BR_FL_18)) #p-value=0.92

mean(twitter[control==1]) #0.45
mean(twitter[positive==1]) #0.48
mean(twitter[negative==1]) #0.54
summary(aov(twitter~RO_BR_FL_18)) #p-value=0.23

mean(white[control==1]) #0.80
mean(white[positive==1]) #0.77
mean(white[negative==1]) #0.86
summary(aov(white~RO_BR_FL_18)) #p-value=0.11

mean(income[control==1]) #55,692.77
mean(income[positive==1]) #50763.47
mean(income[negative==1]) #52754.49
summary(aov(income~RO_BR_FL_18)) #p-value=0.51

mean(interest[control==1]) #3.58
mean(interest[positive==1]) #3.48
mean(interest[negative==1]) #3.69
summary(aov(interest~RO_BR_FL_18)) #p-value=0.12

mean(party[control==1]) #3.12
mean(party[positive==1]) #3.18
mean(party[negative==1]) #3.17
summary(aov(party~RO_BR_FL_18)) #p-value=0.96

mean(na.omit(ideology[control==1])) #2.59
mean(na.omit(ideology[positive==1])) #2.63
mean(na.omit(ideology[negative==1])) #2.54
summary(aov(ideology~RO_BR_FL_18)) #p-value=0.75

mean(white[control==1]) #0.76
mean(white[positive==1]) #0.74
mean(white[negative==1]) #0.83
summary(aov(white~data$RO_BR_FL_18)) #p-value=0.125


#Effective Use of Social Media - higher values=more effective#
table(data$Q78)
socialmediause <- as.numeric(data$Q78)
socialmediause <- recode(socialmediause, "1=5; 2=4; 4=2; 5=1")
table(socialmediause)


#Favorable Impression of Clark - higher values=more favorable#
table(data$Q46)
impression <- as.numeric(data$Q46)
table(impression)
impression <- recode(impression, "1=5; 2=4; 4=2; 5=1", as.factor.result = FALSE, as.numeric.result = TRUE)
table(impression)

#Strong Leader - higher values=stronger leader#
table(data$Q47_1)
strongleader <- as.numeric(data$Q47_1)
table(strongleader)
strongleader <- recode(strongleader, "1=5; 2=4; 4=2; 5=1", as.factor.result = FALSE, as.numeric.result = TRUE)
table(strongleader)


#Trustworthy - higher values=more trustworthy#
table(data$Q47_2)
trustworthy <- as.numeric(data$Q47_2)
table(trustworthy)
trustworthy <- recode(trustworthy, "1=5; 2=4; 4=2; 5=1")
table(trustworthy)


#Knowledgeable - higher values=more knowledgeable#
table(data$Q47_3)
knowledge <- as.numeric(data$Q47_3)
table(knowledge)
knowledge <- recode(knowledge, "1=5; 2=4; 4=2; 5=1")
table(knowledge)


#Electable - higher values=more electable#
table(data$Q47_4)
electable <- as.numeric(data$Q47_4)
table(electable)
electable <- recode(electable, "1=5; 2=4; 4=2; 5=1")
table(electable)

#Caring - ihgher values=more caring#
table(data$Q47_5)
caring <- as.numeric(data$Q47_5)
table(caring)
caring <- recode(caring, "1=5; 2=4; 4=2; 5=1")
table(caring)


#SM presence is Negative - higher values=more negative#
table(data$Q50_1)
negativedv <- as.numeric(data$Q50_1)
table(negativedv)
negativedv <- recode(negativedv, "1=5; 2=4; 4=2; 5=1")
table(negativedv)


#SM presence is Informative - higher values=more informative#
table(data$Q50_2)
informative <- as.numeric(data$Q50_2)
table(informative)
informative <- recode(informative, "1=5; 2=4; 4=2; 5=1")
table(informative)


#SM presence is Credible - higher values=more credible#
table(data$Q50_3)
credible <- as.numeric(data$Q50_3)
table(credible)
credible <- recode(credible, "1=5; 2=4; 4=2; 5=1")
table(credible)


#SM presence is Hostile - higher values=more hostile#
table(data$Q50_4)
hostile <- as.numeric(data$Q50_4)
table(hostile)
hostile <- recode(hostile, "1=5; 2=4; 4=2; 5=1")
table(hostile)

#SM presence is Persuasive - higher values = more persuasive#
table(data$Q50_5)
persuasive <- as.numeric(data$Q50_5)
table(persuasive)
persuasive <- recode(persuasive, "1=5; 2=4; 4=2; 5=1")
table(persuasive)

#Vote for Clark - higher values=more likely to vote Clark#
table(data$Q49)
vote <- as.numeric(data$Q49)
table(vote)
vote <- recode(vote, "1=5; 2=4; 4=2; 5=1")
table(vote)



